﻿package mortal.game.view.guildNew.otherGuild
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.cache.guild.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.menu.*;
    import mortal.game.view.guild.otherpanel.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.game.view.guildNew.otherGuildMem.*;
    import mortal.mvc.core.*;

    public class GuildNewOtherCell extends GCellRenderer
    {
        protected var _bmpRank:GBitmap;
        protected var _nameDes:GTextFiled;
        protected var _level:GTextFiled;
        protected var _mor:GTextFiled;
        protected var num:GTextFiled;
        protected var _totalPower:GTextFiled;
        protected var _notMature:GTextFiled;
        protected var _enter:GButton;
        protected var _applyBtn:GButton;
        protected var _friuts:GBitmap;
        protected var _mature:GTextFiled;
        protected var _line:ScaleBitmap;
        protected var _txtRank:GTextFiled;
        private var _isMyGuildEffect:ScaleBitmap;
        private var _saveData:SMiniGuildInfo;

        public function GuildNewOtherCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bmpRank = UIFactory.gBitmap(ImagesConst.guildNewRank1_icon, 3, 7, this);
            this._nameDes = UIFactory.gTextField("", 34, 7, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._level = UIFactory.gTextField("12", 137, 8, 30, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._mor = UIFactory.gTextField("", 177, 8, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this.num = UIFactory.gTextField("80/80", 257, 8, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._totalPower = UIFactory.gTextField("13246578945", 330, 8, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._notMature = UIFactory.gTextField("" + Language.getString(71570), 469, 7, 100, 20, this, GlobalStyle.textFormatHong);
            this._enter = UIFactory.gButton("" + Language.getString(71571), 582, 4, 67, 25, this);
            this._applyBtn = UIFactory.gButton("" + Language.getString(71572), 656, 5, 67, 25, this);
            this._friuts = UIFactory.gBitmap(ImagesConst.guidlRankFruite2, 436, 6, this);
            this._mature = UIFactory.gTextField("" + Language.getString(71573), 457, 7, 100, 20, this, GlobalStyle.textFormatHuang2);
            this._line = UIFactory.bg(-10, 37, 745, 1, this, ImagesConst.SplitLine);
            this._txtRank = UIFactory.gTextField("3", 4, 7, 20, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._enter.configEventListener(MouseEvent.CLICK, this.onEnterOtherManor);
            this._applyBtn.configEventListener(MouseEvent.CLICK, this.onApplyAdd);
            this.num.htmlText = "<a href=\'event:1\'>80/80</a>";
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bmpRank = null;
            this._nameDes = null;
            this._level = null;
            this._mor = null;
            this.num = null;
            this._totalPower = null;
            this._notMature = null;
            this._enter = null;
            this._applyBtn = null;
            this._friuts = null;
            this._mature = null;
            this._line = null;
            this._txtRank = null;
            this._isMyGuildEffect = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onNumLinkCk(event:TextEvent) : void
        {
            GuildNewUtil.watachGuildId = this._saveData.guildId;
            GuildNewOtherGMemWin.instance.show();
            GuildNewOtherGMemWin.instance.reqInfo();
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:* = param1 as SMiniGuildInfo;
            this._saveData = _loc_2;
            if (_loc_2.guildId == Cache.instance.guild.selfGuildInfo.guildID)
            {
                if (this._isMyGuildEffect == null)
                {
                    this._isMyGuildEffect = UIFactory.bg(0, 0, 725, this.height, this, ImagesConst.selectedBg);
                }
                else
                {
                    this._isMyGuildEffect.visible = true;
                }
            }
            else if (this._isMyGuildEffect)
            {
                this._isMyGuildEffect.visible = false;
            }
            if (_loc_2.rank == 1)
            {
                this._bmpRank.bitmapData = GlobalClass.getBitmapData(ImagesConst.guildNewRank1_icon);
            }
            else if (_loc_2.rank == 2)
            {
                this._bmpRank.bitmapData = GlobalClass.getBitmapData(ImagesConst.guildNewRank2_icon);
            }
            else if (_loc_2.rank == 3)
            {
                this._bmpRank.bitmapData = GlobalClass.getBitmapData(ImagesConst.guildNewRank3_icon);
            }
            else
            {
                this._bmpRank.bitmapData = null;
            }
            this._txtRank.text = _loc_2.rank.toString();
            this._nameDes.htmlText = "<a href=\'event:guildlink\' target = \'\'><font color=\'#ffffff\'><u>" + _loc_2.guildName + "</u></font></a>";
            this._nameDes.configEventListener(TextEvent.LINK, this.onGuildLink);
            this._mor.text = _loc_2.leaderName;
            this._level.text = _loc_2.level.toString();
            this._totalPower.text = _loc_2.combat.toString();
            this.num.htmlText = _loc_2.playerNum + "/" + _loc_2.maxPlayerNum;
            this._enter.visible = true;
            var _loc_3:* = ClockManager.instance.nowDate;
            var _loc_4:* = this._saveData.nextPickUpDt;
            if (_loc_3.time >= _loc_4.time && Cache.instance.guild.selfGuildInfo.baseInfo.level >= 3)
            {
                this._friuts.visible = true;
                this._mature.visible = true;
                this._notMature.visible = false;
            }
            else
            {
                this._friuts.visible = false;
                this._mature.visible = false;
                this._notMature.visible = true;
            }
            this._applyBtn.visible = true;
            this._applyBtn.label = Cache.instance.guild.hasGuild ? ("" + Language.getString(71574)) : (Language.getString(71575));
            if (Cache.instance.guild.hasGuild && Cache.instance.guild.selfGuildInfo.guildID == _loc_2.guildId)
            {
                this._applyBtn.visible = false;
            }
            if (this.canShowInvite())
            {
                this._applyBtn.label = "" + Language.getString(71576);
            }
            if (_loc_2.playerNum == _loc_2.maxPlayerNum)
            {
                this._applyBtn.enabled = false;
                this._applyBtn.filters = [FilterConst.colorFilter2];
            }
            else
            {
                this._applyBtn.enabled = true;
                this._applyBtn.filters = null;
            }
            PlayerMenuRegister.Register(this._mor, _loc_2.leader, PlayerMenuConst.GuildMemberOnlineOpMenu);
            return;
        }// end function

        private function canShowInvite() : Boolean
        {
            var _loc_1:* = Cache.instance.guild.selfGuildInfo;
            if (_loc_1.baseInfo.rank == 1 && EGuildPosition._EGuildLeader == _loc_1.selfInfo.position && ClockManager.instance.serverOpenDateNum >= 3)
            {
                return true;
            }
            return false;
        }// end function

        private function onEnterOtherManor(event:MouseEvent) : void
        {
            if (Cache.instance.guild.hasGuild && this._saveData && Cache.instance.guild.selfGuildInfo.guildID == this._saveData.guildId)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_enterManor, this._saveData.guildId));
                return;
            }
            if (Cache.instance.guild.selfGuildInfo.selfInfo.level < 3)
            {
                MsgManager.showRollTipsMsg("" + Language.getString(71577));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_enterManor, this._saveData.guildId));
            return;
        }// end function

        private function onApplyAdd(event:MouseEvent) : void
        {
            var obj:Object;
            var selfPostion:int;
            var exitCallback:Function;
            var evt:* = event;
            obj = new Object();
            obj.guildID = this._saveData.guildId;
            if (Language.getString(71578) == this._applyBtn.label)
            {
                GuildFindTalentPanel.instance.show();
                GameProxy.guild.getOtherGuildMemberList(this._saveData.guildId);
                return;
            }
            if (Cache.instance.guild.selfGuildInfo.baseInfo)
            {
                selfPostion = Cache.instance.guild.selfGuildInfo.selfInfo.position;
                if (selfPostion >= EGuildPosition._EGuildPresbyter)
                {
                    MsgManager.showRollTipsMsg(Language.getString(71579));
                    return;
                }
                exitCallback = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    obj.guildInfo = _saveData;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_APPLY, obj));
                }
                return;
            }// end function
            ;
                Alert.show(Language.getStringByParam(71580, Cache.instance.guild.selfGuildInfo.baseInfo.guildName), null, Alert.OK | Alert.CANCEL, null, exitCallback);
            }
            else
            {
                obj.guildInfo = this._saveData;
                Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_APPLY, obj));
            }
            return;
        }// end function

        protected function onGuildLink(event:TextEvent) : void
        {
            GuildIntroducePanel.instance.setGuildInfo(this._saveData);
            GuildIntroducePanel.instance.show();
            return;
        }// end function

    }
}
